package dryven.sapi.servlet_v25;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Locale;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import dryven.request.http.AbstractResponse;
import dryven.request.http.Response;

public class ServletResponse extends AbstractResponse {

	private HttpServletResponse _servletResponse;
	
	public ServletResponse(HttpServletResponse servletResponse) {
		super();
		_servletResponse = servletResponse;
	}

	@Override
	public void addCookie(dryven.request.http.Cookie c) {
		Cookie sv = new Cookie(c.getName(), c.getValue());
		sv.setComment(c.getComment());
		sv.setDomain(c.getDomain());
		sv.setMaxAge(c.getMaxAge());
		sv.setPath(c.getPath());
		sv.setSecure(c.isSecure());
		sv.setVersion(c.getVersion());
		_servletResponse.addCookie(sv);
	}

	@Override
	public OutputStream getResponseStream() {
		try {
			return _servletResponse.getOutputStream();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public void setHeader(String name, String value) {
		_servletResponse.setHeader(name, value);
	}

	@Override
	public void setStatus(int status) {
		_servletResponse.setStatus(status);
	}
}
